﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
        Id="Ribbon.Tabs.InfoPathListDisplayTab.VersionHistory"
        Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Tabs.InfoPathListDisplayTab.Groups._children">
          <Group
            Id="Ribbon.Tabs.InfoPathListDisplayTab.VersionGroup"
            Sequence="55"
            Description="Custom Version History Group"
            Title="Version Options"
            Command="EnableVersionGroup"
            Template="Ribbon.Templates.Flexible2">
            <Controls Id="Ribbon.Tabs.InfoPathListDisplayTab.VersionGroup.Controls">
              <Button Id="Ribbon.Tabs.InfoPathListDisplayTab.Manage.Controls.VersionHistoryButton"
               Command="VersionHistoryButtonCommand"
               Sequence="1"
               Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-48" Image16by16Left="-80"
               Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-64" Image32by32Left="-448"
               LabelText="$Resources:core,cui_ButVersionHistory;"
               ToolTipTitle="$Resources:core,cui_ButVersionHistory;"
               ToolTipDescription="$Resources:core,cui_STT_ButItemVersionHistory;"
               TemplateAlias="o2" />
            </Controls>
          </Group>
        </CommandUIDefinition>
        <CommandUIDefinition
          Location="Ribbon.Tabs.InfoPathListDisplayTab.Scaling._children">
          <MaxSize
            Id="Ribbon.Tabs.InfoPathListDisplayTab.Scaling.VersionGroup.MaxSize"
            Sequence="15"
            GroupId="Ribbon.Tabs.InfoPathListDisplayTab.VersionGroup"
            Size="LargeLarge" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="EnableVersionGroup"
          CommandAction="javascript:return true;" />
        <CommandUIHandler
          Command="VersionHistoryButtonCommand"
          CommandAction="javascript:
          function getQueryVariable(qsVariable) {
          var query = window.location.search.substring(1);
          var vars = query.split('&amp;');
           for (var i = 0; i &lt; vars.length; i++) {
           var pair = vars[i].split('=');
            if (pair[0] == qsVariable) {
              return pair[1];
            }
           }
           alert('Error Parsing QueryString!');
          }
          var ListId = getQueryVariable('List');
          var ItemId = getQueryVariable('ID');
          var RedirectUrlString = '{SiteUrl}/_layouts/versions.aspx?list=' + ListId + '&amp;ID=' + ItemId + '&amp;IsDlg=1';
          location.href = RedirectUrlString;"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
